/************************************************************************
 * SSViewer - State Space Viewer for SMLib Library
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * The following component is required for SSViewer: 
 * GLEE.msi (http://research.microsoft.com/research/downloads/Details/f1303e46-965f-401a-87c3-34e1331d32c5/Detailslynn.aspx?0sr=a). 
 * The terms and conditions governing GLEE are contained in the license provided 
 * through the above link apply to your use of GLEE. Any license restrictions 
 * provided in the GLEE license are in addition to, not in lieu of, the terms 
 * and conditions of this license. 
 * IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE.
 * ***********************************************************************
 * File         :     
 * Description  :    
 * Change log   :     
 * To Do        :
 ************************************************************************/
using System;
using SMLib.Automata.IA;
using SMLib.Automata.MM;
using SMLib.Automata.DFA;

namespace Viewer
{
	/// <summary>
	/// Command line utility for state space viewer
	/// </summary>
	class CommandLineUtil
	{
		/// <summary>
		/// Runs with command line.
		/// </summary>
		/// <param name='args'>
		/// Arguments.
		/// </param>
		public static void RunCommandLine (string [] args)
		{
			
		}
		
		/// <summary>
		/// The entry point of the program, where the program control starts and ends.
		/// </summary>
		/// <param name='args'>
		/// The command-line arguments.
		/// </param>
		public static void Main (string[] args)
		{
			Console.WriteLine ("State Space Viewer - command line utility");
			Console.WriteLine ("Usage: \"SysViz -type file.dot\" where:" +
			 	"\n\ttype is in {DFA, IA, MM, or General}\n\tfile.dot is the dot file");
			
			
			#region CHECK GLEE
			string currDir = System.IO.Directory.GetCurrentDirectory ();
			if (!(
				System.IO.File.Exists (currDir + "/Microsoft.GLEE.Drawing.dll")
			   	&&
				System.IO.File.Exists (currDir + "/Microsoft.GLEE.dll")
				&&
				System.IO.File.Exists (currDir + "/Microsoft.Glee.GraphViewerGDI.dll"))
			   ) {
				Console.WriteLine ("Error: GLEE library not found!");
				Console.WriteLine ("The following files are required in the current directory: ");
				Console.WriteLine ("   Microsoft.GLEE.Drawing.dll");
				Console.WriteLine ("   Microsoft.GLEE.dll");
				Console.WriteLine ("   Microsoft.Glee.GraphViewerGDI.dll");
				return;
			}
			   
			
			#endregion
			
			//Console.WriteLine("0:"+args[0]+"1:"+args[1]);
			string t = "";
			string file = "";
			if (args.Length != 2) {
				Console.WriteLine ("Wrong usage!");
				return;
			} else if (!(args [0].Equals ("-DFA") || args [0].Equals ("-IA") || args [0] != "-MM" || args [0] != "-General")) {	
				Console.WriteLine ("Wrong usage! unknown type :" + args [0]);
				return;
			} else if (!(System.IO.File.Exists (args [1]))) {
				Console.WriteLine ("File \"" + args [1] + "\" not found!");
				return;
			}
			
			t = args [0];
			file = args [1];
			//Console.WriteLine("tye="+t+"\nfile="+file);
			
			switch (t) {
			case "-DFA":
				DFA mydfa =
					SMLib.Interoperability.DOT.DotHelper_DFA.ReadFromDOT (file);
				Visualization.AutomataVisualizer.Visualize<DFA.DFA_State, DFA.DFA_Transition> (mydfa);
				break;
				
			case "-IA":
				InterfaceAutomaton ia = 
					SMLib.Interoperability.DOT.DotHelper_IA.ReadFromDot (file);
				Visualization.AutomataVisualizer.Visualize<InterfaceAutomaton.IA_State, InterfaceAutomaton.IA_Step> (ia);
				break;
				
			case "-MM":
				MealyMachine m = 
					SMLib.Interoperability.DOT.DotHelper_MM.ReadFromDot (file);
				Visualization.AutomataVisualizer.Visualize<MealyMachine.Mealy_State, MealyMachine.Mealy_Transition> (m);
				break;
			case "-General":
				Console.WriteLine ("Not implemented yet!");
				break;
			}
		}
	}
}
